//
//  JiaRuView.m
//  XRSquare
//
//  Created by 穆相臣 on 2018/9/5.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "JiaRuView.h"

@interface JiaRuView ()
{
    UIView * contentView;
    
    UILabel * nameLabel;
    UITextField * nameTextField;
    
    NSString * sex;
    UILabel * sexLabel;
    UIButton * maleButton;
    UIButton * femaleButton;
    
    UILabel * idTypeLabel;
    UITextField * idTypeTextField;
    
    UILabel * idNumLabel;
    UITextField * idNumTextField;
    
    UILabel * phoneLabel;
    UITextField * phoneTextField;
    
    UILabel * xueliLabel;
    UITextField * xueliTextField;
    
    UILabel * locationLabel;
    UITextField * locationTextField;
    
    UILabel * bioLabel;
    UITextField * bioTextField;
    
    UILabel * apprLabel;
    UITextField * apprTextField;
    
    UIButton * conform;
    UIButton * remove;
}
@end

@implementation JiaRuView


-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)])
    {
        UIView * black = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        black.alpha = 0.3;
        black.backgroundColor = [UIColor blackColor];
        [self addSubview:black];
        
        contentView = [[UIView alloc]initWithFrame:CGRectMake(30, ScreenHeight/2 - 185, ScreenWidth - 60, 370)];
        contentView.layer.cornerRadius = 10;
        contentView.clipsToBounds = YES;
        contentView.backgroundColor = [UIColor whiteColor];
        [self addSubview:contentView];
        
        UITapGestureRecognizer * tapCanele = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapCancel)];
        UITapGestureRecognizer * tapCanele1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapCancel)];
        [black addGestureRecognizer:tapCanele];
        [contentView addGestureRecognizer:tapCanele1];

        
        nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 50, 100, 20)];
        nameLabel.textAlignment = NSTextAlignmentRight;
        nameLabel.font = [UIFont systemFontOfSize:15];
        nameLabel.text = @"姓名";
        [contentView addSubview:nameLabel];
        
        nameTextField = [[UITextField alloc]initWithFrame:CGRectMake(110, 50, ScreenWidth - 60 - 110, 20)];
        nameTextField.font = [UIFont systemFontOfSize:15];
        [contentView addSubview:nameTextField];
        
        sexLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 80, 100, 20)];
        sexLabel.textAlignment = NSTextAlignmentRight;
        sexLabel.font = [UIFont systemFontOfSize:15];
        sexLabel.text = @"性别";
        [contentView addSubview:sexLabel];
        
        maleButton = [[UIButton alloc]initWithFrame:CGRectMake(110, 80, (ScreenWidth - 60 - 110 - 30)/2, 20)];
        [maleButton setTitle:@"男" forState:UIControlStateNormal];
        maleButton.backgroundColor = [UIColor colorFromHexCode:@"b3b3b3"];
        maleButton.layer.cornerRadius = 10;
        [maleButton addTarget:self action:@selector(maleAction) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:maleButton];

        femaleButton = [[UIButton alloc]initWithFrame:CGRectMake(110 + (ScreenWidth - 60 - 110 - 20)/2, 80, (ScreenWidth - 60 - 110 - 30)/2, 20)];
        [femaleButton setTitle:@"女" forState:UIControlStateNormal];
        femaleButton.backgroundColor = [UIColor colorFromHexCode:@"b3b3b3"];
        femaleButton.layer.cornerRadius = 10;
        [femaleButton addTarget:self action:@selector(femaleAction) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:femaleButton];
        
        idTypeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 110, 100, 20)];
        idTypeLabel.textAlignment = NSTextAlignmentRight;
        idTypeLabel.font = [UIFont systemFontOfSize:15];
        idTypeLabel.text = @"证件类型";
        [contentView addSubview:idTypeLabel];
        
        idTypeTextField = [[UITextField alloc]initWithFrame:CGRectMake(110, 110, ScreenWidth - 60 - 110, 20)];
        idTypeTextField.font = [UIFont systemFontOfSize:15];
        [contentView addSubview:idTypeTextField];
        
        idNumLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 140, 100, 20)];
        idNumLabel.textAlignment = NSTextAlignmentRight;
        idNumLabel.font = [UIFont systemFontOfSize:15];
        idNumLabel.text = @"证件号码";
        [contentView addSubview:idNumLabel];
        
        idNumTextField = [[UITextField alloc]initWithFrame:CGRectMake(110, 140, ScreenWidth - 60 - 110, 20)];
        idNumTextField.font = [UIFont systemFontOfSize:15];
        [contentView addSubview:idNumTextField];
        
        phoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 170, 100, 20)];
        phoneLabel.textAlignment = NSTextAlignmentRight;
        phoneLabel.font = [UIFont systemFontOfSize:15];
        phoneLabel.text = @"联系方式";
        [contentView addSubview:phoneLabel];
        
        phoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(110, 170, ScreenWidth - 60 - 110, 20)];
        phoneTextField.font = [UIFont systemFontOfSize:15];
        [contentView addSubview:phoneTextField];
        
        xueliLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 200, 100, 20)];
        xueliLabel.textAlignment = NSTextAlignmentRight;
        xueliLabel.font = [UIFont systemFontOfSize:15];
        xueliLabel.text = @"最高学历";
        [contentView addSubview:xueliLabel];
        
        xueliTextField = [[UITextField alloc]initWithFrame:CGRectMake(110, 200, ScreenWidth - 60 - 110, 20)];
        xueliTextField.font = [UIFont systemFontOfSize:15];
        [contentView addSubview:xueliTextField];
        
        locationLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 230, 100, 20)];
        locationLabel.textAlignment = NSTextAlignmentRight;
        locationLabel.font = [UIFont systemFontOfSize:15];
        locationLabel.text = @"地址";
        [contentView addSubview:locationLabel];
        
        locationTextField = [[UITextField alloc]initWithFrame:CGRectMake(110, 230, ScreenWidth - 60 - 110, 20)];
        locationTextField.font = [UIFont systemFontOfSize:15];
        [contentView addSubview:locationTextField];
        
        bioLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 260, 100, 20)];
        bioLabel.textAlignment = NSTextAlignmentRight;
        bioLabel.font = [UIFont systemFontOfSize:15];
        bioLabel.text = @"个人简介";
        [contentView addSubview:bioLabel];
        
        bioTextField = [[UITextField alloc]initWithFrame:CGRectMake(110, 260, ScreenWidth - 60 - 110, 20)];
        bioTextField.font = [UIFont systemFontOfSize:15];
        [contentView addSubview:bioTextField];
        
        apprLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 290, 100, 20)];
        apprLabel.textAlignment = NSTextAlignmentRight;
        apprLabel.font = [UIFont systemFontOfSize:15];
        apprLabel.text = @"申请理由";
        [contentView addSubview:apprLabel];
        
        apprTextField = [[UITextField alloc]initWithFrame:CGRectMake(110, 290, ScreenWidth - 60 - 110, 20)];
        apprTextField.font = [UIFont systemFontOfSize:15];
        [contentView addSubview:apprTextField];
        
        conform = [[UIButton alloc]initWithFrame:CGRectMake(contentView.frame.size.width/2 - 30, 320, 60, 30)];
        conform.titleLabel.font = [UIFont systemFontOfSize:15];
        conform.layer.cornerRadius = 15;
        conform.clipsToBounds = YES;
        conform.backgroundColor = themeColor;
        [conform setTitle:@"确认" forState:UIControlStateNormal];
        [conform addTarget:self action:@selector(conformAction) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:conform];
        
        remove = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth - 45, ScreenHeight/2 - 200, 30, 30)];
        [remove setImage:[UIImage imageNamed:@"delete_fill"] forState:UIControlStateNormal];
        [remove addTarget:self action:@selector(removeAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:remove];
    }
    return self;
}

-(void)maleAction
{
    sex = @"0";
    maleButton.selected = YES;
    femaleButton.selected = NO;
    maleButton.backgroundColor = themeColor;
    femaleButton.backgroundColor = [UIColor colorFromHexCode:@"b3b3b3"];
}

-(void)femaleAction
{
    sex = @"1";
    maleButton.selected = NO;
    femaleButton.selected = YES;
    maleButton.backgroundColor = [UIColor colorFromHexCode:@"b3b3b3"];
    femaleButton.backgroundColor = themeColor;
}

-(void)conformAction
{
    if (!sex) {
        [SVProgressHUD showErrorWithStatus:@"请选择性别"];
        return;
    }
   
    [NetRequestCenter companyEnrollWithid:self.contentId touid:idNumTextField.text name:nameTextField.text sex:sex phone:phoneTextField.text province:@"" city:@"" district:@"" companypersonal:@"" address:locationTextField.text brief:bioTextField.text applyreason:apprTextField.text useridtype:idTypeTextField.text userhighdegree:xueliTextField.text companyproperty:@"" companyhangye:@"" result:^(BOOL success, NSDictionary *resultDic) {
        if (success)
        {
            [SVProgressHUD showSuccessWithStatus:@"提交成功"];
            [self removeAction];
        }
        else
        {
            [SVProgressHUD showErrorWithStatus:[resultDic objectForKey:@"message"]];
        }
    }];
}

-(void)tapCancel
{
    [nameTextField resignFirstResponder];
    [idTypeTextField resignFirstResponder];
    [idNumTextField resignFirstResponder];
    [phoneTextField resignFirstResponder];
    [xueliTextField resignFirstResponder];
    [locationTextField resignFirstResponder];
    [bioTextField resignFirstResponder];
    [apprTextField resignFirstResponder];
}

-(void)removeAction
{
    [self.delegate jiaruFinishAction];
    [self removeFromSuperview];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
